function [compressed_img] = compress_img_svd(img, k)
[U,S,V] = svd(double(img));
S_new = S * diag([ones(1,n) ,zeros(1, size(S,2)-n)]);
compressed_img = uint8(U*S_new*V');
function [compressed_img] = compress_img_svd_colored(img, k)
compressed_img(:,:,i) = compress_img_svd(img(:,:,i), k);
function [compressed_img] = compress_img_fft(img, k)
img_f_sorted = sort(abs(img_f(:)));
thr = img_f_sorted(ceil((1-k)*length(img_f_sorted)));
img_cmp = ifft2((abs(img_f) > thr) .* img_f);
compressed_img = uint8(img_cmp);
function [compressed_img] = compress_img_fft_colored(img, k)
compressed_img(:,:,i) = compress_img_fft(img(:,:,i), k);
function Image_Comparing(img)
K = [12, 10, 8, 4, 1, 0.5, 0.1] / 100;
f.Position = [10 10 5000 1000];
imshow(compress_img_svd(img, K(i)))
title(['SVD (coff = ',num2str(K(i)),')'],'Interpreter','latex')
imshow(compress_img_fft(img, K(i)))
title(['FFT (coff = ',num2str(K(i)),')'],'Interpreter','latex')
function Image_Comparing_colored(img)
K = [12, 10, 8, 4, 1, 0.5, 0.1] / 100;
f.Position = [10 10 5000 1000];
imshow(compress_img_svd_colored(img, K(i)))
title(['SVD (coff = ',num2str(K(i)),')'],'Interpreter','latex')
imshow(compress_img_fft_colored(img, K(i)))
title(['FFT (coff = ',num2str(K(i)),')'],'Interpreter','latex')
function [img_rec] = SVD_denoising(colored_img, thr)
for i = 1:size(colored_img,3)
img = colored_img(:,:,i);
[U,S,V] = svd(double(img));
S_new = diag(x .* [(y>thr);0]);
img_rec(:,:,i) = uint8(U*S_new*V');
function SVD_denoising_plot(colored_img)
Thr = [1, 1.5, 2, 2.5, 3];
title('Noisy Image','Interpreter','latex')
imshow(SVD_denoising(colored_img, Thr(i)))
title(['SVD denoising (thr = ',num2str(Thr(i)),')'],'Interpreter','latex')
function [img_rec] = FFT_denoising(colored_img, r)
for i = 1:size(colored_img,3)
img = colored_img(:,:,i);
n = floor(r * size(img,2));
img_rec(:,:,i) = uint8(real(ifft2(img_f)));
function FFT_denoising_plot(colored_img)
R = [0.3, 0.35, 0.4, 0.45, 0.49];
title('Noisy Image','Interpreter','latex')
imshow(FFT_denoising(colored_img, R(i)))
title(['FFT denoising (r = ',num2str(R(i)),')'],'Interpreter','latex')